home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 9 / CDACTUAL9.iso / share / Dos / VARIOS / pascal / FILES.SWG / 0002_WIN95 Long Filenames.pas < prev   
Encoding:
Pascal/Delphi Source File  |  1996-02-21  |  6.8 KB  |  132 lines

  1. {
  2. >>Has anyone done anything to address Win95 long file names yet?
  3. >>I just need to be able to read them 4 now.
  4.  
  5. >I haven't done anything with it, but the current version of Ralf Brown's
  6. >interrupt list describes the way for a DOS program to deal with them.
  7. >(Search for Windows95 *and* Chicago.)  I don't know if that's the best way for
  8. >a Win16 program to deal with them, but it's certainly a possibility.
  9.  
  10. There's actually a typo in release 47 of the list, as I've found out this
  11. evening while trying to handle these in BP (hence the cross-post to
  12. comp.lang.pascal.borland).
  13.  
  14. Here's my BP code for a little program that prints both the short and
  15. long version of any longnamed file on C:.  it'll be pretty similar in Delphi,
  16. if the INT 21 approach is what you're supposed to use in Win16.
  17. }
  18.  
  19. USES Strings;
  20.  
  21. type
  22.   TSearchRec = record                    
  23.     attr : longint;                      
  24.     creation : comp;                     
  25.     lastaccess : comp;                   
  26.     lastmodification : comp;             
  27.     highfilesize : longint;              
  28.     lowfilesize : longint;               
  29.     reserved : comp;                     
  30.     name : array[0..259] of char;        
  31.     shortname : array[0..13] of char;    
  32.     handle : word;                       
  33.   end;                                   
  34.  
  35. const                                    
  36.   faReadOnly      =  $01;                
  37.   faHidden        =  $02;
  38.   faSysFile       =  $04;                
  39.   faVolumeID      =  $08;
  40.   faDirectory     =  $10;                
  41.   faArchive       =  $20;                
  42.   faAnyFile       =  $3F;                
  43.  
  44. function findfirst(filespec:string;attr:word;var S:TSearchRec):integer;  
  45. begin                                                                    
  46.   filespec := filespec + #0;                                             
  47.   S.attr := attr;                                                        
  48.   asm                                                                    
  49.     push ds                                                              
  50.     push ss                                                              
  51.     pop ds                                                               
  52.     lea dx,filespec+1                                                    
  53.     les di,S
  54.     mov ax,$714e                                                         
  55.     mov cx,attr                                                          
  56.     mov si,0
  57.     int $21                                                              
  58.     les di,S
  59.     mov word ptr es:[di+TSearchRec.handle], ax                           
  60.     jc @1                                                                
  61.     xor ax,ax                                                            
  62.   @1:                                                                    
  63.     mov @result,ax                                                       
  64.     pop ds                                                               
  65.   end;                                                                   
  66. end;                                                                     
  67.  
  68.                                                  
  69. function FindNext(var S:TSearchRec):integer;     
  70. begin                                            
  71.   asm                                            
  72.     mov ax,$714f
  73.     mov si,0                                     
  74.     les di,S                                     
  75.     mov bx,word ptr es:[di+TSearchRec.Handle]
  76.     int $21                                      
  77.     jc @1
  78.     xor ax,ax                                    
  79.   @1:                                            
  80.     mov @result,ax                               
  81.   end;                                           
  82. end;                                             
  83.                                                  
  84. function FindClose(var S:TSearchRec):integer;    
  85. begin                                            
  86.   asm                                            
  87.     mov ax,$71a1                                 
  88.     les di,S                                     
  89.     mov bx,word ptr es:[di+TSearchRec.Handle]    
  90.     int $21                                      
  91.     jc @1
  92.     xor ax,ax                                                            
  93.   @1:                                                                    
  94.     mov @result,ax
  95.   end;                                                                   
  96. end;
  97.                                                                          
  98. procedure ShowLongNames(const path:string);                              
  99. var                                                                      
  100.   S : TSearchRec;                                                        
  101.   Res : Integer;                                                         
  102. begin                                                                    
  103.   Res := findfirst(path+'\*.*',faAnyFile-faVolumeID,S);                  
  104.   while Res = 0 do                                                       
  105.   begin                                                                  
  106.     with S do                                                            
  107.     begin                                                                
  108.       if (S.Attr and faDirectory) <> 0 then                              
  109.       begin                                                              
  110.         if (StrComp(Name,'.') <> 0) and (StrComp(Name,'..') <> 0) then
  111.         begin                                                            
  112.           if ShortName[0] <> #0 then                                     
  113.             ShowLongNames(path+'\'+StrPas(ShortName))
  114.           else                                                           
  115.             ShowLongNames(path+'\'+StrPas(Name));
  116.         end;                                                             
  117.       end;                                                               
  118.       if ShortName[0] <> #0 then                                         
  119.         writeln('ren ',path+'\'+StrPas(ShortName),' "',name,'"');        
  120.     end;                                                                 
  121.     Res := FindNext(S);                                                  
  122.   end;                                                                   
  123.   FindClose(S);                                                          
  124. end;                                                                     
  125.                                                                          
  126. var                                                                      
  127.   x : integer;                                                           
  128. begin                                                                    
  129.   showlongnames('D:');
  130. end.
  131.  
  132.